#include "lowpower/include/low_power.h"
#include "include/lp_comcu.h"
#include "comm/co_heartbeat.h"
#include "misc/misc_system.h"
#include "bsp_comm.h"

#include "bsp.h"

#include "global.h"
#define LOG_TAG TAG_LP
#include "elog.h"

/**
 * @brief 休眠使能检测
 * @return 0 - 不能休眠, TASK_ALWAYS_SLEEP - 一直休眠, 其他数值: 可休眠的时间, unit: ms
 */
uint32_t co_mcu_canstop(void)
{
    if (!is_comm_idle())
        return 0; 
    return TASK_ALWAYS_SLEEP;
}

/**
 * @brief 休眠前处理函数
 */
void co_mcu_prestop(void)
{
    bsp_comm_uart_sleep();
}

/**
 * @brief 休眠唤醒后处理函数
 */
void co_mcu_poststop(void)
{
    bsp_comm_uart_wakeup();
}

// 依赖工作模式和激活状态进行配置
sleep_item_t lp_comcu = {
    .name       = "CoMCU", 
    .canstop    = co_mcu_canstop,
    .prestop    = co_mcu_prestop,
    .poststop   = co_mcu_poststop,
};

